//
//  MVVMDemo2ViewController.m
//  DebugDemo
//
//  Created by XFB on 2019/1/7.
//  Copyright © 2019年 ZhouCheng. All rights reserved.
//

#import "MVVMDemo2ViewController.h"
#import "MVVMDemo3ViewController.h"

@interface MVVMDemo2ViewController ()

@property (nonatomic, strong) UILabel *tipLabel;

@end

@implementation MVVMDemo2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupBasicSet];
    [self setupUI];
}

- (void)setupBasicSet
{
    self.navigationItem.title = @"MVVMDemo2";
    self.view.backgroundColor = [UIColor whiteColor];
 
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"MVVMTest" style:UIBarButtonItemStyleDone target:self action:@selector(rightBarButtonItemDidClick:)];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}

- (void)setViewModel:(AnimationViewModel *)viewModel
{
    _viewModel = viewModel;
    
    __weak typeof(self) weakSelf = self;
    _viewModel.changeBlock = ^(AnimationViewModel *viewModel) {
        weakSelf.tipLabel.text = viewModel.greeting;
    };
}

- (void)rightBarButtonItemDidClick:(UIBarButtonItem *)button
{
    [self.viewModel showGreeting];
}

- (void)setupUI
{
    [self.view addSubview:self.tipLabel];
}

- (UILabel *)tipLabel
{
    if (_tipLabel == nil) {
        _tipLabel = [[UILabel alloc] init];
        _tipLabel.frame = CGRectMake(20, NavBarHeight + 40, ScreenW-40, 40);
        _tipLabel.font = [UIFont systemFontOfSize:16];
        _tipLabel.textColor = UIColorFromRGB(0x333333);
        _tipLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _tipLabel;
}

/// 跳转到MVVM ReactCocoa
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    MVVMDemo3ViewController *vc = [[MVVMDemo3ViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
